]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
js/environment: Add GLib spawn async overrides warning when using child setup
authorMarco Trevisan (Treviño) <mail@3v1n0.net>
Tue, 30 Apr 2024 23:17:10 +0000 (01:17 +0200)
committerMarge Bot <marge-bot@gnome.org>
Fri, 24 May 2024 22:48:53 +0000 (22:48 +0000)
Using child setup functions is unsafe in gjs code so let's warn if this
happens so that extensions using a similar codepath are warned.

This could be also part of gjs, but we provide a shell override since we
have alternatives to log about.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3293>

js/ui/environment.js

index 4150542db917d56029d8e9790092338ce384d4a9..4ce70367e90ae2d3617565293f95e5788efbed40 100644 (file)
@@ -345,6 +345,24 @@ if (slowdownEnv) {
         St.Settings.get().slow_down_factor = factor;
 }
 
+function wrapSpawnFunction(func) {
+    const originalFunc = GLib[func];
+    return function (workingDirectory, argv, envp, flags, childSetup, ...args) {
+        if (childSetup) {
+            logError(new Error(`Using child GLib.${func} with a GLib.SpawnChildSetupFunc ` +
+                'is unsafe and may dead-lock, thus it should never be used from JavaScript. ' +
+                `Shell.${func} can be used to perform default actions or an ` +
+                'async-signal-safe alternative should be used instead'));
+        }
+
+        return originalFunc(workingDirectory, argv, envp, flags, childSetup, ...args);
+    };
+}
+GLib.spawn_async = wrapSpawnFunction('spawn_async');
+GLib.spawn_async_with_pipes = wrapSpawnFunction('spawn_async_with_pipes');
+GLib.spawn_async_with_fds = wrapSpawnFunction('spawn_async_with_fds');
+GLib.spawn_async_with_pipes_and_fds = wrapSpawnFunction('spawn_async_with_pipes_and_fds');
+
 // OK, now things are initialized enough that we can import shell JS
 const Format = imports.format;